import QS from "qs"; //引入qs模块，用来序列化post类型的数据
//const BASE_URL = "http://127.0.0.1:4523/mock2/418628"
const BASE_URL = "http://47.113.203.45:82"
export const uploadPic = (url, data, type) => {
	// 默认数据
	const res = {
		code: 500,
		data: null,
		msg: '发送请求失败！'
	}
	return new Promise((resolve, reject) => {
		console.log("uploadPic");
		console.log("网址：",url);
		console.log("图片传来的data",data);
		uni.uploadFile({
		    url: BASE_URL+url,  //https://www.fastmock.site/mock/15d3d3fc7c9b0ea7c09c47e1e8dcb2ee
		    // files: data,
			files: data.file,
		    // name: 'file',

		    success (uploadFileRes) {
				console.log(uploadFileRes.data)
		        resolve(JSON.parse(uploadFileRes.data));
				console.log('--------')
				console.log(data.file)
		    },
			formData:{
				userId: data.userId,
				questionId: data.questionId
			},
		    fail (msg){
		        reject(res);
				console.log(msg);
				console.log('--------')
				console.log(data.file)
		    }
		});
	})
}
